package com.app.megaprosoft.DB;

import java.io.File;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

import com.app.megaprosoft.general.DateTime;
import com.app.megaprosoft.modyimcarcare.Carcare_Login;

import android.app.Application;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.location.Address;
import android.os.Environment;
import android.util.Log;

public class SQLiteDB_ArFF extends SQLiteOpenHelper {

	ResultSet rs = null;
	// Database Version
	private static final int DATABASE_VERSION = 1;

	// Database Name
	private static final String DATABASE_NAME = "MegaAutoCare";

	// Service
	private static final String TABLE_ArFF = "_ArFF";

	public SQLiteDB_ArFF(Context context) {
		super(context, Environment.getExternalStorageDirectory()
				+ File.separator + "/DataBase/" + File.separator
				+ DATABASE_NAME, null, DATABASE_VERSION);
		// TODO Auto-generated constructor stub
	}
	
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// กลุ่มลูกค้า
				try {
					db.execSQL("CREATE TABLE " + TABLE_ArFF
							+ "(ArFFOID TEXT(100) PRIMARY KEY,"

							+ " ArCode TEXT(100)," //1
							+ " ArTitle TEXT(100),"//2
							+ " TitleName TEXT(100)," //3
							+ " ArName TEXT(100),"//4
							+ " ArNickName TEXT(100),"//5

							+ " ArAddr1 TEXT(100)," //6
							+ " ArAddr2 TEXT(100),"//7
							+ " TumbolCode TEXT(100),"//8
							+ " TumbolName TEXT(100),"//9
							+ " AmpurCode TEXT(100),"//10

							+ " AmpurName TEXT(100)," //11
							+ " ProvinceCode TEXT(100),"//12
							+ " ProvinceName TEXT(100)," //13
							+ " BillAdd1 TEXT(100),"//14
							+ " BillAdd2 TEXT(100),"//15

							+ " Telephone TEXT(100),"//16
							+ " Fax TEXT(100),"//17
							+ " Mobile TEXT(100)," //18
							+ " ArGroupOID TEXT(100),"//19
							+ " ArGroupCode TEXT(100),"//20

							+ " ArGroupDesc TEXT(100)," //21
							+ " ArGroupMainOID TEXT(100),"//22
							+ " ArGroupMainCode TEXT(100),"//23
							+ " ArGroupMainDesc TEXT(100),"//24
							+ " IsDisplayWeightDoc TEXT(100),"//25

							+ " ContactDate TEXT(100),"//26
							+ " tmpContactDate TEXT(100),"//27
							+ " FFSaleCode TEXT(100)," //28
							+ " SaleName TEXT(100),"//29
							+ " FFUserCode TEXT(100),"//30

							+ " CreatedBy TEXT(100)," //31
							+ " CreditDay TEXT(100),"//32
							+ " Remark TEXT(100)," //33
							+ " PicPath TEXT(100),"//34
							+ " ArCodeOld TEXT(100),"//35

							+ " ArStatus TEXT(100),"//36 
							+ " DebtLimitBal TEXT(100),"//37
							+ " DebtLimit1 TEXT(100)," //38
							+ " DebtAmount TEXT(100),"//39
							+ " IsPromotion TEXT(100),"//40

							+ " IsRound TEXT(100)," //41
							+ " FFCashier TEXT(100),"//42
							+ " BrokerCode TEXT(100)," //43
							+ " BrokerName TEXT(100),"//44
							+ " BrokerStatus TEXT(100),"//45

							+ " ContractPerson TEXT(100)," //46
							+ " IsCredit TEXT(100),"//47
							+ " IsCreditItem TEXT(100)," //48
							+ " CreditItemDay TEXT(100),"//49
							+ " PaymentMethod TEXT(100),"//50

							+ " PaymentTerms TEXT(100),"//51
							+ " PaymentMethodDesc TEXT(100),"//52
							+ " PaymentTermsDesc TEXT(100)," //53
							+ " CarBandOID TEXT(100),"//54
							+ " VehicleRegistration TEXT(100),"//55

							+ " CarBandName TEXT(100),"//56
							+ " CarGenerationOID TEXT(100),"//57 
							+ " CarType TEXT(100),"//58
							+ " ColorOID TEXT(100)," //59
							+ " CarSize TEXT(100),"//60

							+ " CarGenerationName TEXT(100),"//61
							+ " ColorName TEXT(100),"//62
							+ " CarGroup TEXT(100)," //63
							+ " CarGroupName TEXT(100),"//64

							+ " UserModify TEXT(100)," //65
							+ " CreateTime TEXT(100),"//66
							+ " LastUpdate TEXT(100)," //67
							+ " StatusUpdate TEXT(100),"//68
							+ " IsFavorite TEXT(100));");//69

				} catch (Exception e) {

				}
				try {
					db.execSQL("CREATE TABLE " + TABLE_ArFF
							+ "(ArGroupMainOID TEXT(100) PRIMARY KEY,"
							+ " ArGroupMainCode TEXT(100),"
							+ " ArGroupMainDesc TEXT(100));");
				} catch (Exception e) {

				}
		

		Log.d("CREATE TABLE", "Create Table Successfully.");
	}
	
	
	public void Clear_table() {
		SQLiteDatabase db;
		db = this.getWritableDatabase();
		onUpgrade(db, 0, 1);
	}

	
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_ArFF);
		// Re Create on method onCreate
		onCreate(db);
	}

}
